package org.jeecg.modules.cascv.image.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.cascv.image.entity.GmvIds;
import org.jeecg.modules.cascv.image.service.IGmvIdsService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: ids导入表
 * @Author: jeecg-boot
 * @Date: 2022-08-31
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "ids导入表")
@RestController
@RequestMapping("/test/gmvIds")
public class GmvIdsController extends JeecgController<GmvIds, IGmvIdsService> {
    @Autowired
    private IGmvIdsService gmvIdsService;

    /**
     * 分页列表查询
     *
     * @param gmvIds
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "ids导入表-分页列表查询")
    @ApiOperation(value = "ids导入表-分页列表查询", notes = "ids导入表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(GmvIds gmvIds,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<GmvIds> queryWrapper = QueryGenerator.initQueryWrapper(gmvIds, req.getParameterMap());
        queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0);
        Page<GmvIds> page = new Page<GmvIds>(pageNo, pageSize);
        IPage<GmvIds> pageList = gmvIdsService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param gmvIds
     * @return
     */
    @AutoLog(value = "ids导入表-添加")
    @ApiOperation(value = "ids导入表-添加", notes = "ids导入表-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody GmvIds gmvIds) {
        gmvIdsService.save(gmvIds);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param gmvIds
     * @return
     */
    @AutoLog(value = "ids导入表-编辑")
    @ApiOperation(value = "ids导入表-编辑", notes = "ids导入表-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<?> edit(@RequestBody GmvIds gmvIds) {
        gmvIdsService.updateById(gmvIds);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "ids导入表-通过id删除")
    @ApiOperation(value = "ids导入表-通过id删除", notes = "ids导入表-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        gmvIdsService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "ids导入表-批量删除")
    @ApiOperation(value = "ids导入表-批量删除", notes = "ids导入表-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.gmvIdsService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功！");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "ids导入表-通过id查询")
    @ApiOperation(value = "ids导入表-通过id查询", notes = "ids导入表-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        GmvIds gmvIds = gmvIdsService.getById(id);
        return Result.OK(gmvIds);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param gmvIds
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, GmvIds gmvIds) {
        return super.exportXls(request, gmvIds, GmvIds.class, "ids导入表");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, GmvIds.class);
    }

    /**
     * 通过文件导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @AutoLog(value = "ids导入表-文件导入")
    @ApiOperation(value = "ids导入表-文件导入", notes = "ids导入表-文件导入")
    @RequestMapping(value = "/importFile", method = RequestMethod.POST)
    public Result<?> importFile(HttpServletRequest request, HttpServletResponse response) {
        return gmvIdsService.importFile(request, response, GmvIds.class);
    }

}
